package com.enhe.gck.fg;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.enhe.gck.com.oracle.LwdHttpConfig;
import com.enhe.gck.com.oracle.OracleEntity;
import com.enhe.gck.com.oracle.OracleService;
import com.enhe.gck.communal.PublicMethod;
import com.enhe.gck.communal.PublicReturn;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;
import com.kuangkie.carbon.fg.FuncGroupContext;
import com.kuangkie.carbon.fg.ImproveResultFactory;
import com.kuangkie.carbon.fg.SecondRoundImproveFuncGroup;
import com.kuangkie.carbon.record.FGRecordComplexus;
import com.kuangkie.carbon.record.ProRecord;
import com.enhe.gck.CarbonBaseConstant; //模型Code
import com.enhe.gck.CarbonEnumKeyValue; //枚举字典信息
import com.enhe.gck.CarbonRelationType; //关系类型Code
import com.enhe.gck.item.ErrorRecordHWANE17164Item; // 模型属性Code

import javax.annotation.Resource;
import java.util.List;
@Slf4j
@Repository(value = "hwane17164366042330866425862")
public class ErrorRecordHWANE17164BNB implements SecondRoundImproveFuncGroup{
	@Resource
	private OracleService oracleService;

	@Override
	public void secondImprove(FuncGroupContext context, ProRecord proRecord, FGRecordComplexus recordComplexus,
			ImproveResultFactory improveResultFactory) {
		log.info("添加失败信息");
		if(proRecord.getLongValue(ErrorRecordHWANE17164Item.基本属性组_命令)==CarbonEnumKeyValue.操作命令_发送记录_重发_fsjlzf){
			if(proRecord.getBoolean(ErrorRecordHWANE17164Item.基本属性组_是否成功)){
				PublicMethod.returnMessage(improveResultFactory, PublicReturn.ErrorRecord_2);
				return;
			}
			repeat(proRecord,improveResultFactory);
		}
	}

	private void repeat(ProRecord proRecord,ImproveResultFactory improveResultFactory){
		OracleEntity.ReturnData r=new OracleEntity.ReturnData();
		String type=proRecord.getString(ErrorRecordHWANE17164Item.基本属性组_类型);
		String data=proRecord.getString(ErrorRecordHWANE17164Item.基本属性组_发送数据);
		if(String.valueOf(CarbonEnumKeyValue.调用接口_获取供应商_hqgys).equals(type)){
			r =oracleService.sendGetDataRequestString(LwdHttpConfig.abutmentSupplierUrl,data);
		}
		if(String.valueOf(CarbonEnumKeyValue.调用接口_获取销售商_hqxss).equals(type)){
			r =oracleService.sendGetDataRequestString(LwdHttpConfig.abutmentCompanyUrl,data);
		}
		if(String.valueOf(CarbonEnumKeyValue.调用接口_获取物料信息_hqwlxx).equals(type)){
			r =oracleService.sendGetDataRequestString(LwdHttpConfig.abutmentMaterialUrl,data);
		}
		if(String.valueOf(CarbonEnumKeyValue.调用接口_发送充值信息_fsczxx).equals(type)){
			List<OracleEntity.Recharge> info= JSONArray.parseArray(data,OracleEntity.Recharge.class);
			r.setOk(oracleService.saveRecharge(info,false));
		}
		if(String.valueOf(CarbonEnumKeyValue.调用接口_删除销售发货_scxsfh).equals(type)){
			OracleEntity.DeleteOrder info=JSONObject.parseObject(data,OracleEntity.DeleteOrder.class);
			r.setOk(oracleService.deleteOrder(info,false));
		}
		if(String.valueOf(CarbonEnumKeyValue.调用接口_发送销售发货_fsxsfh).equals(type)){
			List<OracleEntity.Order> info= JSONArray.parseArray(data,OracleEntity.Order.class);
			r.setOk(oracleService.saveOrder(info,false,true));
		}
		if(String.valueOf(CarbonEnumKeyValue.调用接口_发送提货点信息_fsthdxx).equals(type)){
			List<OracleEntity.Pickup> info= JSONArray.parseArray(data,OracleEntity.Pickup.class);
			r.setOk(oracleService.savePickup(info,false));
		}
		if(r.isOk()){
			improveResultFactory.getCurrentProRecordOpsBuilder().putAttribute(ErrorRecordHWANE17164Item.基本属性组_是否成功,true);
		}else {
			PublicMethod.returnMessage(improveResultFactory, PublicReturn.ErrorRecord_1);
		}
	}
}
